home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / cmdline.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-19  |  6.4 KB  |  291 lines

  1. /* cmdline.cpp
  2.  
  3.    Command line version of maplay written by John Fehr
  4.  
  5.    This can be used for unix systems as well as the Win32 console. */
  6.  
  7. #ifdef __WIN32__
  8. #define  STRICT
  9. #include <windows.h>
  10. #endif // __WIN32__
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <iostream.h>
  15.  
  16. #include "all.h"
  17. #include "crc.h"
  18. #include "args.h"
  19.  
  20. // What character marks the end of a directory entry? For DOS and
  21. // Windows, it is "\"; in UNIX it is "/".
  22. #ifdef __WIN32__
  23. #define DIR_MARKER '\\'
  24. #else
  25. #define DIR_MARKER '/'
  26. #endif
  27.  
  28. #ifdef __WIN32__
  29. HWAVEOUT hwo;
  30. #endif
  31.  
  32. BOOL verbose_mode = FALSE;
  33. char filename[512] = "";
  34.  
  35. uint32 maplay(MPEG_Args *);
  36.  
  37. int ProcessArgs(int argc,char *argv[],MPEG_Args *);
  38.  
  39. int Usage(char *pname)
  40. {
  41.     cerr << "\nusage: " << pname
  42.      << " [-v] [-s] [-l] [-r] "
  43. #ifdef SPARC
  44.         "[-us] [-uh] "
  45. #ifndef SunOS4_1_1
  46.         "[-ul] "
  47. #endif
  48. #endif
  49.         "[-f ushort] filename\n"
  50.         "  filename   filename of a MPEG audio stream or - for stdin\n"
  51. #ifdef VERBOSE
  52.         "  -v         verbose mode\n"
  53. #endif
  54. #ifdef ULAW
  55.         "  -s         write u-law samples at 8 kHz rate to stdout\n"
  56. #else
  57.         "  -s         write pcm samples to stdout\n"
  58. #endif
  59.         "  -l         decode only the left channel\n"
  60.         "  -r         decode only the right channel\n"
  61.         "  -d         downmix mode (layer III only)\n"
  62. #ifdef SPARC
  63.         "  -us        send audio signal to speaker (default)\n"
  64.         "  -uh        send audio signal to headphone\n"
  65. #ifndef SunOS4_1_1
  66.         "  -ul        send audio signal to line out\n"
  67. #endif
  68. #endif
  69. #ifdef ULAW
  70.         "  -amd       force maplay to treat /dev/audio as an amd device\n"
  71. #endif
  72. #ifdef VERBOSE
  73.         "  -c         check for filter range violations\n"
  74. #endif
  75.         "  -f ushort  use this scalefactor instead of the default value 32768\n\n"
  76.         "@(#) MPEG Audio Player maplay 1.2+ "
  77. #ifdef ULAW
  78.         "(8 kHz u-law "
  79. #else
  80.         "("
  81. #endif
  82. #ifdef Indigo
  83.         "SGI IRIX"
  84. #else
  85. #ifdef SunOS4_1_1
  86.         "SPARC SunOS 4.1.1"
  87. #else
  88. #ifdef SunOS4_1_3
  89.         "SPARC SunOS 4.1.3"
  90. #else
  91. #ifdef Solaris
  92.         "SPARC Solaris 2.x"
  93. #else
  94. #ifdef LINUX
  95.         "Linux"
  96. #else
  97. #ifdef ULTRIX
  98.         "RISC ULTRIX 4.x"
  99. #else
  100. #ifdef HPUX
  101.         "HPUX 10.10"
  102. #else
  103. #ifdef AIX
  104.         "AIX"
  105. #else
  106. #ifdef NeXT
  107.         "NeXTStep 3.2"
  108. #else
  109. #ifdef __WIN32__
  110.         "Win32 Console"
  111. #else
  112.         "unknown"
  113. #endif  // _WIN32__       
  114. #endif  // NeXT
  115. #endif  // AIX
  116. #endif  // HPUX
  117. #endif  // ULTRIX
  118. #endif  // LINUX
  119. #endif  // Solaris
  120. #endif  // SunOS4_1_3
  121. #endif  // SunOS4_1_1
  122. #endif  // Indigo
  123.  
  124.         " version)\n"
  125.         "@(#) Copyright (C) 1996, 1997 Jeff Tsay (ctsay@pasteur.eecs.berkeley.edu)\n"
  126.          "@(#) This re-ported commandline version 1.81 by John Fehr (jfehr@themall.net)\n"
  127.        "@(#)\n"
  128.         "@(#) Original maplay 1.2:\n"
  129.         "@(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\n"
  130.         "@(#) Berlin University of Technology\n"
  131.        "@(#)\n"
  132.         "@(#) Layer III code adapted from the ISO MPEG Audio Subgroup Software\n"
  133.        "@(#) Simulation Group\n"
  134.        "@(#)\n"       
  135.         "@(#) Created: 04/19/97 (Pentium version)\n"
  136.         "@(#) This program is free software. See the GNU General Public License\n"
  137.         "@(#) in the file COPYING for more details.\n\n"
  138.         ;
  139.     return 0;
  140.   }
  141.  
  142. int ProcessArgs(int32 argc,char *argv[],MPEG_Args *ma)
  143. {
  144.  
  145.   Crc16 *crc = NULL;
  146.   int i;
  147.  
  148.   ma->stdout_mode = FALSE;
  149.  
  150. #ifdef __WIN32__
  151.   ma->phwo = &hwo;
  152. #endif
  153.  
  154.   if (argc < 2 || !strncmp (argv[1], "-h", 2))
  155.   {
  156.     return Usage(argv[0]);
  157.   }
  158.   // parse arguments:
  159.   for (i = 1; i < argc; ++i)
  160.     if (argv[i][0] == '-' && argv[i][1])
  161.       switch ((int32)argv[i][1])
  162.       {
  163.     case 'v':
  164. #ifdef VERBOSE
  165.       verbose_mode = TRUE;
  166. #else
  167.       cerr << "maplay: not compiled with VERBOSE." << endl;
  168. #endif
  169.       break;
  170.     case 's':
  171.       ma->stdout_mode = TRUE;
  172.       break;
  173.     case 'l':
  174.       ma->which_c = left;
  175.       break;
  176.     case 'r':
  177.       ma->which_c = right;
  178.       break;
  179.    case 'd':
  180.       ma->which_c = downmix;
  181.      break;
  182.  
  183. #ifdef SPARC
  184.     case 'u':
  185.       switch (argv[i][2])
  186.       {
  187.         case 's':
  188.           ma->use_speaker = TRUE;
  189.           break;
  190.         case 'h':
  191.           ma->use_headphone = TRUE;
  192.           break;
  193. #ifndef SunOS4_1_1
  194.         case 'l':
  195.           ma->use_line_out = TRUE;
  196.           break;
  197. #endif
  198.         default:
  199.           return Usage(argv[0]);
  200.       }
  201.       break;
  202. #endif
  203. #ifdef ULAW
  204.     case 'a':
  205.       ma->force_amd = TRUE;
  206.       break;
  207. #endif
  208.     case 'c':
  209.      cerr << "Sorry, this version does not support filter checking.\n" << endl;
  210.       break;
  211.     case 'f':
  212.       if (++i == argc)
  213.       {
  214.         cerr << "please specify a new scalefactor after the -f option!\n";
  215.         exit (1);
  216.       }
  217.       ma->use_own_scalefactor = TRUE;
  218.       sscanf (argv[i], "%f", &ma->scalefactor);
  219.       break;
  220.     default:
  221.       return Usage(argv[0]);
  222.       }
  223.     else if (!filename[0])
  224.       strcpy(filename,argv[i]);
  225.     else
  226.       return Usage(argv[0]);
  227.  
  228.   if (!filename[0])
  229.     return Usage(argv[0]);
  230.  
  231. #if defined(SPARC) || defined(HPUX)
  232.   if (!(ma->use_speaker || ma->use_headphone || ma->use_line_out))
  233.     ma->use_speaker = TRUE;
  234. #endif // SPARC || HPUX
  235.  
  236.   if (!strcmp (filename, "-"))
  237.     ma->stream = new Ibitstream (0);        // read from stdin
  238.   else
  239.     ma->stream = new Ibitstream (filename);        // read from file
  240.  
  241.   ma->MPEGheader = new Header;
  242.   if (!ma->MPEGheader->read_header (ma->stream, &crc))
  243.   {
  244.     cerr << endl <<  "Error : no header found!" << endl;
  245.     return(0);
  246.   }
  247.   return(1);
  248. }
  249.  
  250. int maplay_setup (MPEG_Args *ma)
  251. {
  252.  
  253. #ifdef VERBOSE
  254.   if (verbose_mode)
  255.   {
  256.     // print information about the stream
  257.     char *name = strrchr (filename, DIR_MARKER);
  258.     if (name)
  259.       ++name;
  260.     else
  261.       name = filename;
  262.     cerr << name << " is a layer " << ma->MPEGheader->layer_string () << ' '
  263.      << ma->MPEGheader->mode_string () << " MPEG audio stream with";
  264.     if (!ma->MPEGheader->checksums ())
  265.       cerr << "out";
  266.     cerr << " checksums.\nThe sample frequency is "
  267.      << ma->MPEGheader->sample_frequency_string () << " at a bitrate of "
  268.      << ma->MPEGheader->bitrate_string () << ".\n"
  269.         "This stream is ";
  270.     if (ma->MPEGheader->original ())
  271.       cerr << "an original";
  272.     else
  273.       cerr << "a copy";
  274.     cerr << " and is ";
  275.     if (!ma->MPEGheader->copyright ())
  276.       cerr << "not ";
  277.     cerr << "copyright protected.\n";
  278.   }
  279. #endif
  280.   return(1);
  281. }
  282.  
  283. int main(int argc,char *argv[])
  284. {
  285.     MPEG_Args ma;
  286.     if (!ProcessArgs(argc,argv,&ma)) return(0);
  287.     maplay_setup(&ma);
  288.     maplay(&ma);
  289.    return(0);
  290. }
  291.